package com.mida.dms.knw.controller;

import com.mida.dms.knw.entity.KnwIndividual;
import com.mida.dms.knw.entity.vo.KnwIndividualVo;
import com.mida.dms.knw.entity.vo.KnwIndividualVos;
import com.mida.dms.knw.entity.vo.KnwSlotVo;
import com.mida.dms.knw.service.KnwIndividualService;
import com.mida.dms.knw.vo.IndividualParmVo;
import com.mida.dms.knw.vo.KnwIndividualPageVo;
import com.mida.dms.knw.vo.PageResultVo;
import com.mida.tool.common.result.ActionResult;
import com.mida.tool.common.result.ListResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.mida.dms.knw.Result.BaseResult.buildActionWarn;

/**
 * 实例控制器
 * 如需扩展返回或传入参数 请修改泛型的第一个参数
 * 如需扩展分页查询条件请修改泛型的第二个参数，必须继承PageSearchVo 具体可以参考com.mida.dms.knw.entity.vo.DataSetVo
 * @author conyfrommars
 *
 */
@RestController
@RequestMapping("/knwIndividual")
@Api(tags = "实例")
@Slf4j
@CrossOrigin
public class KnwIndividualController implements BaseControl<KnwIndividual, KnwIndividualPageVo> {

	@Autowired
	private KnwIndividualService knwIndividualService;

	@ApiOperation(value = "新增实例", notes = "新增实例")
	@PostMapping(value = "/addKnwIndividual",produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	@Override
	public ActionResult add(KnwIndividual t) {
		// TODO Auto-generated method stub
		return null;
	}

	@ApiOperation(value = "更新实例", notes = "更新实例")
	@PostMapping(value = "/updateKnwIndividual",produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	@Override
	public ActionResult update(KnwIndividual t) {
		// TODO Auto-generated method stub
		return null;
	}

	@ApiOperation(value = "保存实例", notes = "保存实例")
	@PostMapping(value = "/saveKnwIndividual",produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ActionResult save(@RequestBody KnwIndividualVo t) {
		ActionResult result = new ActionResult();
		try {
			result= knwIndividualService.save(t);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			buildActionWarn(result, "保存实例失败");
		}
		return result;
	}

	@ApiOperation(value = "删除实例", notes = "删除实例")
	@ApiImplicitParam(name = "soid", value = "实例soid", required = false)
	@GetMapping(value = "/deleteKnwIndividual")
	@ResponseBody
	@Override
	public ActionResult delete(long soid) {
		// TODO Auto-generated method stub
		ActionResult result = new ActionResult();
		try {
			result= knwIndividualService.delete(soid);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			buildActionWarn(result, "删除实例失败");
		}
		return result;
	}

	@ApiOperation(value = "获取实例", notes = "获取实例")
	@ApiImplicitParam(name = "soid", value = "实例soid", required = false)
	@GetMapping(value = "/getKnwIndividual")
	@ResponseBody
	@Override
	public ListResult<KnwIndividual> get(long soid) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 *分页查询实例
	 */
	@ApiOperation(value = "分页查询实例", notes = "分页查询实例")
	@PostMapping(value = "/findPage",produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	@Override
	public ListResult<PageResultVo<KnwIndividualVo>> findPage(@RequestBody KnwIndividualPageVo vo) {
		//分页查询实例
		return knwIndividualService.findPage(vo);
	}

	/**
	 * 查询本体下所有实例
	 */
	@ApiOperation(value = "查询本体下所有实例", notes = "查询本体下所有实例")
	@PostMapping(value = "/findAll",produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ListResult<List<KnwIndividualVo>> findAll(@RequestBody KnwIndividualPageVo vo) {
		//查询本体下所有实例
		return knwIndividualService.findAll(vo);
	}

	/**
	 * 批量禁用
	 * @return
	 */
	@GetMapping(value = "/stopSize")
	public ActionResult stopSize(@RequestParam(name = "soids", required = true) String soids){

		ActionResult result = new ActionResult();
		try {
			return knwIndividualService.stopSize(soids);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			buildActionWarn(result, "批量禁用失败");
		}
		return result;
	}
	/**
	 * 批量启用
	 * @return
	 */
	@GetMapping(value = "/openSize")
	public ActionResult openSize(@RequestParam(name = "soids", required = true) String soids){

		ActionResult result = new ActionResult();
		try {
			return knwIndividualService.openSize(soids);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			buildActionWarn(result, "批量启用失败");
		}
		return result;

	}

	/**
	 * 初始化实例生成页面
	 * @param noumenonSoid
	 * @return
	 */
	@ApiOperation(value = "查询所有本体Slot下对应的编码体系", notes = "查询所有本体Slot下对应的编码体系")
	@GetMapping(value = "/showIndividualInit")
	@ResponseBody
	public ListResult<List<KnwSlotVo>> showIndividualInit(@RequestParam Long noumenonSoid) {
		return knwIndividualService.showIndividualInit(noumenonSoid);
	}

	/**
	 * 实例列表生成
	 * @param individualParmVo
	 * @return
	 */
	@PostMapping(value = "/getIndividualList",produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ListResult<List<KnwSlotVo>> getIndividualList(@RequestBody IndividualParmVo individualParmVo) {
		return knwIndividualService.getIndividualList(individualParmVo);
	}

	@ApiOperation(value = "批量保存实例", notes = "批量保存实例")
	@PostMapping(value = "/saveKnwIndividualSolt",produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ActionResult saveKnwIndividualSolt(@RequestBody KnwIndividualVos t) {
		ActionResult result = new ActionResult();
		try {
			result= knwIndividualService.saveKnwIndividualSolt(t);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			buildActionWarn(result, "批量保存实例失败");
		}
		return result;
	}
}
